package com.kingdee.eas.xbang.preparehandle.impl.app;

import org.apache.log4j.Logger;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.eas.common.EASBizException;

public class BusinessVoucherPrepareControllerBean extends AbstractBusinessVoucherPrepareControllerBean {
	private static Logger logger = Logger.getLogger("com.kingdee.eas.xbang.preparehandle.impl.app.BusinessVoucherPrepareControllerBean");

	protected IObjectPK _addnew(Context ctx, IObjectValue model) throws BOSException, EASBizException {
		_checkNumberDup(ctx, model);
		return super._addnew(ctx, model);
	}

	protected void _checkNumberDup(Context ctx, IObjectValue model) throws BOSException, EASBizException {
		FilterInfo filter = new FilterInfo();
		FilterItemInfo filterItem = new FilterItemInfo("number", model.getString("number"), CompareType.EQUALS);
		filter.getFilterItems().add(filterItem);
		if (model.getString("id") != null) {
			filterItem = new FilterItemInfo("id", model.getString("id"), CompareType.NOTEQUALS);
			filter.getFilterItems().add(filterItem);
		}
		EntityViewInfo view = new EntityViewInfo();
		view.setFilter(filter);
		if (super._exists(ctx, filter)) {
			throw new EASBizException(EASBizException.CHECKDUPLICATED, new Object[] { model.getString("number") });
		} else {
			return;
		}
	}
}